import Vuex from 'vuex'
import aixos from 'axios'

export default Vuex.createStore({
    state:{
        name:'游客'
    },
    mutations:{
        setName(state,newName){
            state.name = newName
        }
    },
    actions:{
        setNameByAction(context,{name,password}){
            aixos({
                url:'/api/user/login',
                method:'post',
                data:{
                    name:name,
                    password:password
                },
            }).then(res=>{
                console.log(res)
                console.log(res.data)
                context.commit('setName',res.data)
            }).catch(err=>{
                console.log(err)
            })
        }
    }
})